#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>


int main(int argc, const char *argv[])
{
	mkfifo("./pipe1",0664);
	mkfifo("./pipe2",0664);

	int fd1=open("./pipe1",O_RDWR);
	int fd2=open("./pipe2",O_RDWR);

	pid_t pid=fork();
	if(pid==0)
	{
		close(fd2);
		char writebuf[32];
		while(1)
		{
			//scanf("%s",writebuf);
			fgets(writebuf,32,stdin);
			write(fd1,writebuf,32);
		}
	}
	else if(pid>0)
	{
		close(fd1);
		char readbuf[32];
		while(1)
		{
			int len=read(fd2,readbuf,32);
			if(len>0)
			{
				printf("%s\n",readbuf);
			}
		}
	}

	return 0;
}
